﻿using System.Linq;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class Software_RequestFormDetailInfo
    {
        #region /*Không thay đổi*/
        public bds m_bds = new bds();
        private DBMain m_data = new DBMain();
        private bool m_bExist = true;

        public bool ExistInDataBase
        {
            get { return this.m_bExist; }
        }
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
            m_data.m_DCSave.SubmitChanges();
        }
        #endregion /*Không thay đổi*/

        #region [Properties - Thuộc tính]

        public Software_RequestFormDetail Properties
        {
            get { return m_bds.Current as Software_RequestFormDetail; }
        }
        #endregion

        public Software_RequestFormDetailInfo(int _iSoftware_RequestFormDetailKey = -1)
        {
            var iQuery = this.m_data.m_DCSave.Software_RequestFormDetails.Where(p => p.Software_RequestFormDetailKey == _iSoftware_RequestFormDetailKey);
            m_bds.DataSource = iQuery;
            var Row = iQuery.FirstOrDefault();
            this.m_bExist = true;
            if (Row == null)
            {
                this.m_bExist = false;
                Row = new Software_RequestFormDetail();
                m_bds.Add(Row);
            }
        }        
    }
}
